package com.zhss.eshop.commodity.mapper;

import com.zhss.eshop.commodity.domain.model.CommodityPropertyGroupRelationship;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommodityPropertyGroupRelationshipMapper {
    int deleteByPrimaryKey(Long id);

    int insertSelective(CommodityPropertyGroupRelationship record);

    CommodityPropertyGroupRelationship selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(CommodityPropertyGroupRelationship record);

    /**
     * 根据属性分组id查询属性分组与属性的关联关系
     * @param propertyGroupId 属性分组id
     * @return 属性分组与属性的关联关系
     */
    @Select("SELECT "
            + "id,"
            + "property_group_id,"
            + "property_id,"
            + "is_required,"
            + "property_types,"
            + "gmt_create,"
            + "gmt_modified "
            + "FROM commodity_property_group_relationship "
            + "WHERE property_group_id=#{propertyGroupId} ")
    @Results({
            @Result(column = "id", property = "id", id = true),
            @Result(column = "property_group_id", property = "propertyGroupId"),
            @Result(column = "property_id", property = "propertyId"),
            @Result(column = "is_required", property = "required"),
            @Result(column = "property_types", property = "propertyTypes"),
            @Result(column = "gmt_create", property = "gmtCreate"),
            @Result(column = "gmt_modified", property = "gmtModified")
    })
    List<CommodityPropertyGroupRelationship> listByPropertyGroupId(
            @Param("propertyGroupId") Long propertyGroupId);

    /**
     * 根据属性分组id删除属性分组与属性的关联关系
     * @param propertyGroupId 属性分组id
     */
    @Delete("DELETE FROM commodity_property_group_relationship "
            + "WHERE property_group_id=#{propertyGroupId}")
    void removeByPropertyGroupId(@Param("propertyGroupId") Long propertyGroupId);
}
